<?php

class M_system_check Extends MY_Model
{
	private $missing_tables = array();

	public function check()
	{
		if(
			$this->_exists('adviser_remarks') AND
			$this->_exists('announcements') AND
			$this->_exists('attendance') AND
			$this->_exists('contracts') AND
			$this->_exists('custodian_items') AND
			$this->_exists('custodian_items_categories') AND
			$this->_exists('custodian_items_transactions') AND
			$this->_exists('employees') AND
			$this->_exists('enrolled_subjects') AND
			$this->_exists('enrolled_subject_grades') AND
			$this->_exists('enrollments') AND
			$this->_exists('fees') AND
			$this->_exists('grade_level_sections') AND
			$this->_exists('grading_periods') AND
			$this->_exists('lessons') AND
			$this->_exists('lesson_files') AND
			$this->_exists('let_gov_exams') AND
			$this->_exists('levels') AND
			$this->_exists('level_fees') AND
			$this->_exists('library_books') AND
			$this->_exists('library_book_category') AND
			$this->_exists('online_settings') AND
			$this->_exists('payment_reports') AND
			$this->_exists('profiles') AND
			$this->_exists('rooms') AND
			$this->_exists('schedule') AND
			$this->_exists('school_calendar') AND
			$this->_exists('school_settings') AND
			$this->_exists('school_years') AND
			$this->_exists('sections') AND
			$this->_exists('section_subjects') AND
			$this->_exists('student_deductions_record') AND
			$this->_exists('student_enrollment_fees') AND
			$this->_exists('student_grades') AND
			$this->_exists('student_payment_breakdown') AND
			$this->_exists('student_payment_records') AND
			$this->_exists('student_scholarships') AND
			$this->_exists('student_scholarship_record') AND
			$this->_exists('student_subjects') AND
			$this->_exists('subjects') AND
			$this->_exists('time') AND
			$this->_exists('users') AND
			$this->_exists('system_settings')
			)
		{
			return TRUE;
		}else{
			return FALSE;
		}
	}
	
	
	private function _exists($x)
	{
		if($this->db->table_exists($x)){
			return TRUE;
		}else{
			$this->missing_tables[] = $x;
			return FALSE;
		}
	}
	
	public function get_missing_tables()
	{
		return $this->missing_tables;
	}
	
	public function show_settings()
	{
		$result = $this->db->get('system_settings');
		return $result->result();
	}
	
	public function update_settings($data)
	{
		unset($data['update_system_settings']);
		
		if(!empty($data))
		{
			$this->db->set($data)->update('system_settings');		
			return $this->db->affected_rows() == count($data) ? TRUE : FALSE;
		}else{
			return FALSE;
		}
	}
}